<!doctype html>
<html xmlns:th="http://www.thymeleaf.org">
<body>
<script th:inline="javascript">
    var editable = [(${editable})];

    function initPaperNoFieldChange() {
        var oldValue = ""; // 一个不存在的值
        var sint = setInterval(function(){
            if (fo("[(${fieldNo})]")) {
                if (oldValue != fo("[(${fieldNo})]").value) {
                    oldValue = fo("[(${fieldNo})]").value;
                    onPaperNoCtlChange();
                }
            } else {
                window.clearInterval(sint);
            }
        },500);

        var oldValueYear = ""; // 一个不存在的值
        var sintYear = setInterval(function(){
            if (fo("[(${fieldYear})]")) {
                if (oldValueYear != fo("[(${fieldYear})]").value) {
                    oldValueYear = fo("[(${fieldYear})]").value;
                    onPaperNoCtlChange();
                }
            } else {
                window.clearInterval(sintYear);
            }
        },500);
    }

    if (editable) {
        initPaperNoFieldChange();
    }

    function onPaperNoCtlChange() {
        if (fo("[(${fieldNo})]") && fo("[(${fieldNo})]").value=="") {
            fo("[(${fieldName})]").value = "";
            return;
        }

        // 查看详情时
        if (!fo("[(${fieldNo})]").value || !fo("[(${fieldYear})]").value) {
            return;
        }

        var ajaxData = {
            op: "getNo",
            flowId: "[(${flowId})]",
            fieldName: "[(${fieldName})]",
            [(${fieldNo})]: fo("[(${fieldNo})]").value,
            [(${fieldYear})]: fo("[(${fieldYear})]").value,
        };
        $.ajax({
            type: "post",
            url: "../../flow/macro/getPaperno",
            data: ajaxData,
            dataType: "json",
            success: function (res, status) {
                console.log('res', res);
                if (res.code == 200) {
                    o("[(${fieldName})]").value = res.data.num;
                } else {
                    mui.toast(res.msg);
                }
            },
            error: function (XMLHttpRequest, textStatus) {
                //alert(XMLHttpRequest.responseText);
            }
        })
    }
</script>
</body>
</html>